/*     */ package com.zimbra.cs.account.accesscontrol;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.GuestAccount;
/*     */ import com.zimbra.cs.account.MailTarget;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AccessControlUtil
/*     */ {
/*     */   public static boolean isGlobalAdmin(Account acct)
/*     */   {
/*  31 */     return isGlobalAdmin(acct, true);
/*     */   }
/*     */   
/*     */   public static boolean isGlobalAdmin(MailTarget target, boolean asAdmin) {
/*  35 */     if ((!asAdmin) || (target == null) || (!(target instanceof Account))) {
/*  36 */       return false;
/*     */     }
/*  38 */     return ((Account)target).isIsAdminAccount();
/*     */   }
/*     */   
/*     */   public static boolean isGlobalAdmin(Account acct, boolean asAdmin) {
/*  42 */     return (asAdmin) && (acct != null) && (acct.isIsAdminAccount());
/*     */   }
/*     */   
/*     */   static boolean isDelegatedAdmin(Account acct, boolean asAdmin) {
/*  46 */     return (asAdmin) && (acct != null) && (acct.isIsDelegatedAdminAccount());
/*     */   }
/*     */   
/*     */   public static Account authTokenToAccount(AuthToken authToken, Right rightNeeded) {
/*  50 */     Account granteeAcct = null;
/*     */     try
/*     */     {
/*  53 */       if (authToken == null) {
/*  54 */         if (rightNeeded.isUserRight()) {
/*  55 */           granteeAcct = GuestAccount.ANONYMOUS_ACCT;
/*     */         }
/*  57 */       } else if (authToken.isZimbraUser()) {
/*  58 */         granteeAcct = authToken.getAccount();
/*     */       }
/*  60 */       else if (rightNeeded.isUserRight()) {
/*  61 */         granteeAcct = new GuestAccount(authToken);
/*     */       }
/*     */     }
/*     */     catch (ServiceException e) {
/*  65 */       ZimbraLog.acl.warn("unable to get account from auth token, id=: " + authToken.getAccountId(), e);
/*     */     }
/*     */     
/*     */ 
/*  69 */     return granteeAcct;
/*     */   }
/*     */   
/*     */   public static MailTarget emailAddrToMailTarget(String emailAddr, Right rightNeeded) {
/*  73 */     MailTarget grantee = null;
/*  74 */     if (emailAddr != null) {
/*     */       try {
/*  76 */         grantee = Provisioning.getInstance().get(Key.AccountBy.name, emailAddr);
/*     */       }
/*     */       catch (ServiceException e) {}
/*  79 */       if (grantee == null) {
/*     */         try {
/*  81 */           grantee = Provisioning.getInstance().get(Key.DistributionListBy.name, emailAddr);
/*     */         } catch (ServiceException e) {
/*  83 */           ZimbraLog.acl.warn("unable to get account or distribution list from email address: " + emailAddr, e);
/*     */         }
/*     */       }
/*     */     }
/*  87 */     if (grantee == null)
/*     */     {
/*  89 */       if (rightNeeded.isUserRight()) {
/*  90 */         if (emailAddr != null) {
/*  91 */           grantee = new GuestAccount(emailAddr, null);
/*     */         } else {
/*  93 */           grantee = GuestAccount.ANONYMOUS_ACCT;
/*     */         }
/*     */       }
/*     */     }
/*  97 */     return grantee;
/*     */   }
/*     */   
/*     */   public static Account emailAddrToAccount(String emailAddr, Right rightNeeded) {
/* 101 */     Account granteeAcct = null;
/*     */     try {
/* 103 */       if (emailAddr != null) {
/* 104 */         granteeAcct = Provisioning.getInstance().get(Key.AccountBy.name, emailAddr);
/*     */       }
/*     */       
/* 107 */       if (granteeAcct == null)
/*     */       {
/* 109 */         if (rightNeeded.isUserRight()) {
/* 110 */           if (emailAddr != null) {
/* 111 */             granteeAcct = new GuestAccount(emailAddr, null);
/*     */           } else {
/* 113 */             granteeAcct = GuestAccount.ANONYMOUS_ACCT;
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */     catch (ServiceException e) {
/* 119 */       ZimbraLog.acl.warn("unable to get account from email address: " + emailAddr, e);
/*     */     }
/*     */     
/* 122 */     return granteeAcct;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/accesscontrol/AccessControlUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */